/* 
 * File:   tracer.cpp
 * Author: alexey
 * 
 * Created on 5 Апрель 2011 г., 18:14
 */

#include "tracer.h"
#include <string>
#include "boost/date_time/posix_time/posix_time.hpp"
using namespace storagemon;
using namespace boost::posix_time;
using namespace boost::gregorian;

tracer::tracer() : m_level(TraceLavelDebug), m_console(false)
{

}

tracer::~tracer()
{
}

void tracer::SetLevel(TraceLevel level)
{
    m_level = level;
}
void tracer::Open(const char* target)
{
    std::string m_target = target;
    if (m_target.compare("console") == 0)
        m_console = true;
    else
        m_file.open(target);
}
void tracer::Write(const char* data, TraceLevel level)
{
    if (level >= m_level)
    {
        ptime now = second_clock::local_time();
        if (m_console)
            std::cout << now << " " << data << "\n";
        else
            m_file << now << " " << data << "\n";
    }
}
void tracer::Close()
{
    if (!m_console)
        m_file.close();
}

